package com.acme;


import com.acme.NFLAwards.NFLAwardsResponseReceiver;
import com.acme.PlayerProfile.PlayerProfileResponseReceiver;

import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class CollegeAwards extends ListActivity {

	private CollegeAwardsResponseReceiver receiver;
	
	public class CollegeAwardsResponseReceiver extends BroadcastReceiver {
		   @Override
		    public void onReceive(Context context, Intent intent) {
		       	String response = intent.getStringExtra(FootballStatsService.GET_AWARDS_OUT_JSON);
		       	String[] awards = Awards.getAwards(response);
		        setListAdapter(
		        	new ArrayAdapter<String>(
		        		CollegeAwards.this.getApplicationContext(),
		        		R.layout.text_list_item, 
		        		awards
		        	)
		        );
		    }
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_list);  
        
        String awardtype = "college";
        
		IntentFilter filter = new IntentFilter(FootballStatsService.GET_AWARDS_RESP);
		filter.addCategory(Intent.CATEGORY_DEFAULT);
		receiver = new CollegeAwardsResponseReceiver();
		registerReceiver(receiver, filter);

		Intent msgIntent = new Intent(this, FootballStatsService.class);
		msgIntent.putExtra(FootballStatsService.ACTION,FootballStatsService.ACTION_GET_AWARDS);
		msgIntent.putExtra(FootballStatsService.GET_AWARDS_IN_TYPE, awardtype);
		startService(msgIntent);
     
    }
		
	public void onListItemClick(ListView parent, View view, int position, long id) {
		String selected = (String) this.getListAdapter().getItem(position);
		Intent newIntent = new Intent(this, AwardWinners.class);
		newIntent.putExtra(AwardWinner.AWARD_NAME, selected);
		startActivity(newIntent);
	}
	
	public void onDestroy(){
		super.onDestroy();
		unregisterReceiver(receiver);
	}
}
